package com.pubinfo.passbook.common.model.vo.system;

import com.pubinfo.passbook.common.entity.TSubsidiaryInfo;
import com.pubinfo.passbook.common.entity.TSystemRole;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author litiewang
 * @Date 2022/6/2 9:28
 * @Version 1.0
 */
@Data
@NoArgsConstructor
@ApiModel(value = "UserRoleVo", description = "用户角色信息")
public class UserRoleVo extends TSystemRole implements Serializable {
  @ApiModelProperty("组织id")
  private Long orgId;
  @ApiModelProperty("用户角色唯一id")
  private String userRoleId;
  
  public UserRoleVo(TSystemRole role) {
    BeanUtils.copyProperties(role, this);
  }
  
  public UserRoleVo(TSubsidiaryInfo info) {
    this.nsrsbh = info.getNsrsbh();
    this.districtId = info.getDistrictId();
    this.roleCode = "passbook_bill_auditor";
    this.roleName = info.getName() + "-医药费审核员";
  }
  
  public static List<UserRoleVo> convertRole(List<TSystemRole> roles) {
    List<UserRoleVo> voList = new ArrayList<>();
    if (!CollectionUtils.isEmpty(roles)) {
      roles.stream().forEach(role -> {
        UserRoleVo vo = new UserRoleVo(role);
        voList.add(vo);
      });
    }
    return voList;
  }
}
